package com.hunlian.makelove.net.api;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hunlian.makelove.bean.ContactModel;
import com.hunlian.makelove.net.ServiceInterfaceDef;
import com.hunlian.makelove.net.InterfaceServiceVisit;
import com.hunlian.makelove.net.ResponseCallbackListener;
import com.hunlian.makelove.net.StringResponseCallbackListener;

import java.lang.reflect.Type;
import java.util.ArrayList;


/**
 * 联系人
 * @author zealjiang
 * @time 2016/8/29 18:53
 */
public class ContactServiceVisit extends InterfaceServiceVisit {


	public ContactServiceVisit(Context context) {
		super(context);

		setFunctionId(ServiceInterfaceDef.FUNC_ID_CONTACT);
	}

	// 填充参数
	public void setParamters() {

	}

	public void getResult(final ResponseCallbackListener<ArrayList<ContactModel.BeansBean>,Object> listener) {
		doPost(getParamter(), new StringResponseCallbackListener() {
			@Override
			public void onSuccess(String data) {
				//Printout.println("联系人反馈 :"+data);
			
				Type listType = new TypeToken<ArrayList<ContactModel.BeansBean>>(){}.getType();
				Gson gson = new Gson();
				ArrayList<ContactModel.BeansBean> listData = gson.fromJson(data, listType);

				if(listener != null){
					listener.onSuccess(listData);
				}
			}

			@Override
			public void onFailure(String errCode, String errMessage,String errData) {
				if (listener != null) {
					if(null!=errData){
						listener.onFailure(errCode, errMessage,null);
					}else{
						listener.onFailure(errCode, errMessage,null);
					}

				}
			}
		});
	}


}
